/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.i.kotionokyurievna.jewelryweb.entities;

import java.io.Serializable;
import javax.persistence.*;
import ua.i.kotionokyurievna.jewelryweb.entities.Department;

/**
 *
 * @author Kateryna_Reznik
 */
@Entity
@NamedQueries({
    @NamedQuery ( name = "Job.findById",
        query="SELECT j.jobId, j.jobTitle, j.minSalary, j.maxSalary, "
        + "j.department "
        + "FROM Job j "
        + "WHERE j.jobId = :jobId"),
    @NamedQuery ( name = "Job.findByJobTitle",
        query="SELECT j.jobId, j.jobTitle, j.minSalary, j.maxSalary, "
        + "j.department "
        + "FROM Job j "
        + "WHERE j.jobTitle = :jobTitle"),
    @NamedQuery ( name = "Job.findBySalary",
        query="SELECT j.jobId, j.jobTitle, j.minSalary, j.maxSalary, "
        + "j.department "
        + "FROM Job j "
        + "WHERE j.minSalary <= :jobSalary AND j.maxSalary >= :jobSalary"),
    @NamedQuery ( name = "Job.findByMinSalary",
        query="SELECT j.jobId, j.jobTitle, j.minSalary, j.maxSalary, "
        + "j.department "
        + "FROM Job j "
        + "WHERE j.minSalary = :jobMinSalary"),
    @NamedQuery ( name = "Job.findByMaxSalary",
        query="SELECT j.jobId, j.jobTitle, j.minSalary, j.maxSalary, "
        + "j.department "
        + "FROM Job j "
        + "WHERE j.maxSalary = :jobSalary"),
    @NamedQuery ( name = "Job.findByDepartmentId",
        query="SELECT j.jobId, j.jobTitle, j.minSalary, j.maxSalary, "
        + "j.department "
        + "FROM Job j "
        + "WHERE j.department = :department")
    
})
@Table (name = "jobs")
public class Job implements Serializable{
    @Id 
    @Column( name = "job_id")
    @GeneratedValue (strategy = GenerationType.TABLE)
    private int jobId;
    @Column ( name = "job_title" )
    private String jobTitle;
    @Column (name = "min_salary")
    private double minSalary;
    @Column ( name = "max_salary")
    private double maxSalary;
    @ManyToOne
    @JoinColumn( name = "department_id")
    private Department department;

    public Job() {
    }

    public Job(String jobTitle, double minSalary, double maxSalary, Department department) {
        this.jobTitle = jobTitle;
        this.minSalary = minSalary;
        this.maxSalary = maxSalary;
        this.department = department;
    }

    public Job(int jobId, String jobTitle, double minSalary, double maxSalary, Department department) {
        this.jobId = jobId;
        this.jobTitle = jobTitle;
        this.minSalary = minSalary;
        this.maxSalary = maxSalary;
        this.department = department;
    }

    public int getJobId() {
        return jobId;
    }

    public void setJobId(int jobId) {
        this.jobId = jobId;
    }

    public String getJobTitle() {
        return jobTitle;
    }

    public void setJobTitle(String jobTitle) {
        this.jobTitle = jobTitle;
    }

    public double getMinSalary() {
        return minSalary;
    }

    public void setMinSalary(double minSalary) {
        this.minSalary = minSalary;
    }

    public double getMaxSalary() {
        return maxSalary;
    }

    public void setMaxSalary(double maxSalary) {
        this.maxSalary = maxSalary;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    @Override
    public String toString() {
        return "Job{" + "jobId=" + jobId + ", jobTitle=" + jobTitle + 
                ", minSalary=" + minSalary + ", maxSalary=" + maxSalary + 
                ", department=" + department + '}';
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.jobTitle != null ? this.jobTitle.hashCode() : 0);
        hash = 97 * hash + (this.department != null ? this.department.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Job other = (Job) obj;
        if ((this.jobTitle == null) ? (other.jobTitle != null) : 
                !this.jobTitle.equals(other.jobTitle)) {
            return false;
        }
        if (this.department != other.department && (this.department == null || 
                !this.department.equals(other.department))) {
            return false;
        }
        return true;
    }
    
    
}
